#include "game.h"
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")

/**
 * Laduje zasob.
 */
bool Image::load()
{
	if(surface)
		unload();

	D3DXIMAGE_INFO info;
	if(FAILED(D3DXGetImageInfoFromFileInMemory(getData(), getDataSize(), &info)))
		return false;

	width = info.Width;
	height = info.Height;

	if(FAILED(Game::getGraphics()->getDevice()->CreateOffscreenPlainSurface(
		info.Width, info.Height, info.Format, D3DPOOL_DEFAULT, &surface, NULL)))
		return false;

	if(FAILED(D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL,
		getData(), getDataSize(), NULL, D3DX_DEFAULT, 0, NULL)))
		return false;

	return true;
}


/**
 * ...
 */
void Image::unload()
{
	if(surface)
	{
		surface->Release();
		surface = NULL;
		width = 0;
		height = 0;
	}
}
